 <div class="well">
       <form role="form" class="form-inline">
           <div class="form-group">
              <div class="input-group m-b">
                  <span class="input-group-addon">Chuyên mục</span>
                  <select name="cat_id" id="input-type" class="form-control m-b">
                     <option value="0">Tất cả</option>
                     <?php if (isset($menu_tree) && $menu_tree) foreach ($menu_tree as $menu) print_menu_select($menu); ?>
                 </select>
             </div>
         </div>
         <div class="form-group">
          <label for="input-search" class="sr-only">Search</label>
          <input name="keyword" id="input-search" type="text" placeholder="Type your keyword" class="form-control">
      </div>
      <div class="form-group">
          <div class="input-group m-b">
              <select name="type" id="input-type" class="form-control m-b">
                 <option value="0">Tất cả</option>
             </select>
             <span id="searchBtn" class="btn input-group-addon"><i class="fa fa-search"></i></span>
         </div>
     </div>
 </form>
</div>
 <div class="panel panel-default">				
	<div class="panel-heading"><em class="fa <?php echo $this->post->get_post_status_icon($post_status);?>"></em> <?php echo $this->heading;?>
		<a href="#" data-perform="panel-dismiss" data-toggle="tooltip" title="Close Panel" class="pull-right">
			<em class="fa fa-times"></em>
		</a>
		<a href="#" data-perform="panel-collapse" data-toggle="tooltip" title="Collapse Panel" class="pull-right">
			<em class="fa fa-minus"></em>
		</a>
	</div>
	
	<div class="panel-top">
	</div>
	<div class="panel-body">
		<div class="table-responsive">
			<table id="listpost" class="table table-bordered table-hover">
				<thead>
					<tr>
						<th style="width: 30%;">Tiêu đề</th>
						<th style="width: 10%;">Ngày tạo</th>
                        <?php if($up_title != '') { ?> 
						<th style="width: 8%;"><?php echo $up_title;?></th>
                        <?php } ?>
                        <?php if($down_title != '') { ?> 
						<th style="width: 8%;"><?php echo $down_title;?></th>
                        <?php } ?>
						<th style="width: 13%;">Tạo - Sửa</th>
						<th style="width: 10%;"></th>
						<th style="width: 16%;"></th>
						<th style="width: 5%;" class="check-all">
							<div data-toggle="tooltip" data-title="Check All" class="checkbox c-checkbox">
								<label>
									<input type="checkbox">
									<span class="fa fa-check"></span>
								</label>
							</div>
						</th>
					</tr>
				</thead>
			</table>
		</div>				
	</div>

</div>
	 
 

<script type="text/javascript">
(function($, window, document){
  'use strict';

	var Selector = 'th.check-all';

  	$(Selector).on('change', function() {
	    var $this = $(this),
	        index= $this.index() + 1,
	        checkbox = $this.find('input[type="checkbox"]'),
	        table = $this.parents('table');
	    // Make sure to affect only the correct checkbox column
	    table.find('tbody > tr > td:nth-child('+index+') input[type="checkbox"]').prop('checked', checkbox[0].checked);
  	});

  	$(document).on('click', '[data-updateList="true"]', function(){
  		$('#listpost').DataTable().ajax.reload();
  	});

    $(document).on('click', '[data-toogle="status"]', function() {
        var $this = $(this),
            type = $this.data('type'),
            postid = $this.data('postid'),
            status = $this.data('status');
        var _url = "<?php echo admin_url();?>posts/change_status/" + postid + '/' + status+'/'+type+'/' + '/1';
        $.ajax({
            type: "POST",
            url: _url,
            //data: {},
            async: false,
            success: function(res) {
                if(res == true)
                {

                    $.notify("Cập nhật thành công!", 'success');
                     $('#listpost').DataTable().ajax.reload();
                }
                else
                {
                    $.notify(res, 'danger');
                }
                    
               
            }       
        });
    });


  	$(document).on('click', '[data-removePost="true"]', function() {
  		//deleterows();
  		var listpost = $('#listpost').DataTable();
  		$.ajax({
            type: "POST",
            url: "<?php echo admin_url();?>posts",
            data: listpost.$('input:checked').serialize(),
            async: false,
            success: function(res) {
                res = $.parseJSON(res);
                console.log(res);
                if(res.status == false)
                	$.notify("Cập nhật thất bại!", 'danger');
                else
                	$.notify("Cập nhật thành công!", 'success');
                $('#listpost').DataTable().ajax.reload();
            }       
        });
  	});

}(jQuery, window, document));
</script>


<script type="text/javascript">
$(document).ready(function() {
    var listpost = $('#listpost').dataTable( {
		dom: '<"top"fl>rt<"bottom"pi><"clear">',
		processing: true,
        serverSide: true,
        ajax: {
                "url": "<?php echo $config['ajax']['url']; ?>",
                "type": "POST",
                data: function(d) {
                    d.status = <?php echo $post_status; ?>;
                    d.cat_id = $('select[name=cat_id]').val();
                     d.keyword = $('input[name=keyword]').val();
                },
                async: true/*,
                success: function(response) {
                    console.log(response);
                }*/
            },
		columns: [
			{ 
                "data": 'post_title',
                "orderable": false,
                "render": function ( data, type, full, meta ) {
                	var str = data + '<br><strong>' + full.post_category + '</strong> <span class="label label-info">' + full.count_word + '</span>';
                	return str;
                }
            },
            { 
                "data": 'post_create_date',
                "orderable": false
            },
            <?php if($up_title != '') { ?> 
            { 
                "class": "text-center",
                "data": 'post_id',
                "orderable": false,
                "render": function ( data, type, full, meta ) {
	                var str = '<a href="javascript:void(0);" data-toogle="status" data-postid="'+data+'" data-status="'+full.post_status+'"  data-type="up" title="<?php echo $up_title;?>"><i class="fa fa-arrow-up fa-2x" style="color: green;"></i></a>';
	                return str;
	            }
            },
            <?php } ?>
            <?php if($down_title != '') { ?> 
            { 
                "class": "text-center",
                "data": 'post_id',
                "orderable": false,
                "render": function ( data, type, full, meta ) {
	                var str = '<a href="javascript:void(0);" data-toogle="status" data-postid="'+data+'"data-status="'+full.post_status+'" data-type="down" title="<?php echo $down_title;?>"><i class="fa fa-arrow-down fa-2x" style="color: red;"></i></a>';
	                return str;
	            }
            },
            <?php } ?>
            { 
                "data": 'author',
                "orderable": false,
                "render": function ( data, type, full, meta ) {
                	var str = data + '<br><strong>' + full.editby + '</strong>';
                	return str;
                }
            },
            { 
                "class": "text-center",
                "data": 'lockby',
                "orderable": false,
                "render": function ( data, type, full, meta ) {
                    if(data =='')
                    var str = '<span class="label label-primary">Đóng</span>';
                else
                	var str = '<span class="label label-warning">'+data+'</span>';
                	return str;
                }
            },
            { 
                "class": "text-center",
                "data": 'post_id',
                "orderable": false,
                "render": function ( data, type, full, meta ) {
                	var str = '<a href="<?php echo $this->url_edit; ?>'+ data +'"><button type="button" class="btn btn-labeled btn-success btn-xs"><span class="btn-label"><i class="fa fa-pencil"></i></span>Sửa</button></a> ';
                	str += '<button type="button" class="btn btn-labeled btn-info btn-xs"><span class="btn-label"><i class="fa fa-compass"></i></span>Truy vết</button>';
                	return str;
                }
            },
            { 
                "class": "text-center",
                "data": 'post_id',
                "orderable": false,
                "render": function ( data, type, full, meta ) {
                	var str = "";
                	str += '<div class="checkbox c-checkbox">';
                    str += ' 	<label>';
                    str += '    	<input type="checkbox" name="post_id[]" value="'+data+'">';
                    str += '    	<span class="fa fa-check"></span>';
                    str += ' 	</label>';
                  	str += '</div>';
                  	return str;
                }
            }
		]
    } );
	
	var listpost = $('#listpost').DataTable();
    $(document).on('click', '#searchBtn', function(){
        $('#listpost').DataTable().ajax.reload();
    });
});
</script>

<style>
	.table>caption+thead>tr:first-child>td, .table>caption+thead>tr:first-child>th, .table>colgroup+thead>tr:first-child>td, .table>colgroup+thead>tr:first-child>th, .table>thead:first-child>tr:first-child>td, .table>thead:first-child>tr:first-child>th {
	  	border: 1px solid #ddd;
	}
	.form-inline th .checkbox input[type=checkbox], .form-inline th .radio input[type=radio] {
		position: absolute;
	}
</style>